<template>
  <!-- <a-drawer width="35%" :label-col="4" :wrapper-col="14" :visible="open" @close="onClose">
     <a-divider orientation="left">
       <b>{{ formTitle }}</b>
     </a-divider> -->
  <a-modal :visible="open" :title="formTitle" @cancel="onClose">
    <a-form-model ref="form" :model="form" :rules="rules">
      <a-form-model-item label="物流公司id" prop="deptId" >
        <a-input v-model="form.deptId" placeholder="请输入物流公司id" />
      </a-form-model-item>
      <a-form-model-item label="车辆ID" prop="carId" >
        <a-input v-model="form.carId" placeholder="请输入车辆ID" />
      </a-form-model-item>
      <a-form-model-item label="订单ID" prop="orderId" >
        <a-input v-model="form.orderId" placeholder="请输入订单ID" />
      </a-form-model-item>
      <a-form-model-item label="物流公司名称" prop="wlgs" >
        <a-input v-model="form.wlgs" placeholder="请输入物流公司名称" />
      </a-form-model-item>
      <a-form-model-item label="司纳税人识别号" prop="identificationNo" >
        <a-input v-model="form.identificationNo" placeholder="请输入司纳税人识别号" />
      </a-form-model-item>
      <a-form-model-item label="物流公司信息(地址电话)" prop="wlgsInfo" >
        <a-input v-model="form.wlgsInfo" placeholder="请输入内容" type="textarea" allow-clear />
      </a-form-model-item>
      <a-form-model-item label="发车信息" prop="begin" >
        <a-input v-model="form.begin" placeholder="请输入发车信息" />
      </a-form-model-item>
      <a-form-model-item label="到车信息" prop="end" >
        <a-input v-model="form.end" placeholder="请输入到车信息" />
      </a-form-model-item>
      <a-form-model-item label="车辆信息" prop="vehicleInfo" >
        <a-input v-model="form.vehicleInfo" placeholder="请输入车辆信息" />
      </a-form-model-item>
      <a-form-model-item label="状态;状态" prop="status" >
      </a-form-model-item>
      <a-form-model-item label="删除标识;删除标志" prop="delFlag" v-if="formType === 1">
        <a-input v-model="form.delFlag" placeholder="请输入删除标识;删除标志" />
      </a-form-model-item>
      <a-form-model-item label="备注" prop="remark" >
        <a-input v-model="form.remark" placeholder="请输入备注" />
      </a-form-model-item>
      <a-form-model-item label="发车-到车时间:2024年6月1日--2024年6月30日" prop="peekDate" >
        <a-input v-model="form.peekDate" placeholder="请输入发车-到车时间:2024年6月1日--2024年6月30日" />
      </a-form-model-item>
      <a-form-model-item label="数字金额" prop="pay" >
        <a-input v-model="form.pay" placeholder="请输入数字金额" />
      </a-form-model-item>
      <a-form-model-item label="文字金额" prop="payUpCase" >
        <a-input v-model="form.payUpCase" placeholder="请输入文字金额" />
      </a-form-model-item>
    </a-form-model>
    <template slot="footer">
        <a-space>
          <a-button type="primary" :loading="submitLoading" @click="submitForm">
            保存
          </a-button>
          <a-button type="dashed" @click="cancel">
            取消
          </a-button>
        </a-space>
    </template>
  </a-modal>
  <!-- </a-drawer> -->
</template>

<script>
import { getInfo, addInfo, updateInfo } from '@/api/vehicle/contract'

export default {
  name: 'CreateForm',
  props: {
  },
  components: {
  },
  data () {
    return {
      submitLoading: false,
      formTitle: '',
      // 表单参数
      form: {
        id: null,

        deptId: null,

        carId: null,

        orderId: null,

        wlgs: null,

        identificationNo: null,

        wlgsInfo: null,

        begin: null,

        end: null,

        vehicleInfo: null,

        status: '0',

        createBy: null,

        createTime: null,

        updateBy: null,

        updateTime: null,

        delFlag: null,

        remark: null,

        peekDate: null,

        pay: null,

        payUpCase: null

      },
      // 1增加,2修改
      formType: 1,
      open: false,
      rules: {
        status: [
          { required: true, message: '状态;状态不能为空', trigger: 'blur' }
        ],

        delFlag: [
          { required: true, message: '删除标识;删除标志不能为空', trigger: 'blur' }
        ]

      }
    }
  },
  filters: {
  },
  created () {
  },
  computed: {
  },
  watch: {
  },
  mounted () {
  },
  methods: {
    onClose () {
      this.open = false
    },
    // 取消按钮
    cancel () {
      this.open = false
      this.reset()
    },
    // 表单重置
    reset () {
      this.formType = 1
      this.form = {
        id: null,

        deptId: null,

        carId: null,

        orderId: null,

        wlgs: null,

        identificationNo: null,

        wlgsInfo: null,

        begin: null,

        end: null,

        vehicleInfo: null,

        status: '0',

        createBy: null,

        createTime: null,

        updateBy: null,

        updateTime: null,

        delFlag: null,

        remark: null,

        peekDate: null,

        pay: null,

        payUpCase: null

      }
    },
    /** 新增按钮操作 */
    handleAdd (row) {
      this.reset()
      this.formType = 1
      this.open = true
      this.formTitle = '添加'
    },
    /** 修改按钮操作 */
    handleUpdate (row, ids) {
      this.reset()
      this.formType = 2
      const id = row ? row.id : ids
      getInfo(id).then(response => {
        this.form = response.data
        this.open = true
        this.formTitle = '修改'
      })
    },
    /** 提交按钮 */
    submitForm: function () {
      this.$refs.form.validate(valid => {
        if (valid) {
          this.submitLoading = true
          if (this.form.id !== undefined && this.form.id !== null) {
            updateInfo(this.form).then(response => {
              this.$message.success(
                '修改成功',
                3
              )
              this.open = false
              this.$emit('ok')
            }).finally(() => {
              this.submitLoading = false
            })
          } else {
            addInfo(this.form).then(response => {
              this.$message.success(
                '新增成功',
                3
              )
              this.open = false
              this.$emit('ok')
            }).finally(() => {
              this.submitLoading = false
            })
          }
        } else {
          return false
        }
      })
    }
  }
}
</script>
